package br.com.werp.regras.geral.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import br.com.werp.regras.geral.integracao.MasterDAO;


/**
 * @author Sobreira
 * Criado em 26/01/2005
 * 
 */
public class ListaJars {
    public static void main(String[] args) throws Exception {
//        File file = new File("libs");
//        File[] files = file.listFiles();
//        for (int i = 0; i < files.length; i++) {
//            System.out.println("<pathelement location=\"libs/"+
//                    files[i].getName()+"\"/>");
//        }
        Connection conn = MasterDAO.getConexao();
        File file = new File("matrix.mp3");
 
        if (false){
        FileInputStream fis = new FileInputStream(file);
        PreparedStatement ps = conn.prepareStatement(
                "INSERT INTO teste_binary VALUES (?, ?)");
        System.out.println(file.length());
        ps.setBinaryStream(1, fis, (int) file.length());
        ps.setString(2, file.getName());
        ps.executeUpdate();
        ps.close();
        fis.close();
        }
        if (true){
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        PreparedStatement ps = conn.prepareStatement(
                "SELECT data FROM teste_binary WHERE nome=?");
        ps.setString(1, file.getName());
        ResultSet rs = ps.executeQuery();
        if (rs != null) {
            while(rs.next()) {
                byte[] imgBytes = rs.getBytes(1);
                fileOutputStream.write(imgBytes);
            }
            rs.close();
        }
        ps.close();
        fileOutputStream.close();
    }
    }
}
